package com.xzg.myMission.controller;

import com.xzg.common.constants.Constant;
import com.xzg.common.exception.XZGException;
import com.xzg.common.page.PageQueryBean;
import com.xzg.common.resp.APIResult;
import com.xzg.common.vo.QueryCondition;
import com.xzg.mission.entity.Mission;
import com.xzg.myMission.entity.MyMission;
import com.xzg.myMission.server.MyMissionService;
import com.xzg.user.entity.User;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("/myMission")
public class MyMissionController {

    @Autowired
    private MyMissionService myMissionService;

    @RequestMapping("/check")
    @ResponseBody
    public PageQueryBean checkMyMission(@RequestBody QueryCondition condition) {
        User user = (User) SecurityUtils.getSubject().getSession().getAttribute("userinfo");
        String[] range = condition.getRangeDate().split("/");
        condition.setStartDate(range[0]);
        condition.setEndDate(range[1]);
//        User user = new User();
//        user.setId(2l);
        condition.setUserId(user.getId());
        PageQueryBean result = myMissionService.findAllMission(condition);
        return result;
    }

    @RequestMapping("/findOne")
    @ResponseBody
    public APIResult findOne(@RequestBody QueryCondition condition) throws XZGException {
        APIResult resp = new APIResult();
        MyMission myMission = myMissionService.findOne(condition.getMissionId());
        if (myMission != null) {
            resp.setCode(Constant.RESP_STATUS_OK);
            resp.setMessage("查询成功");
            resp.setData(myMission);
        }
        return resp;
    }
}
